﻿from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

url = r'http://172.16.22.105:8080/bsams/front/login.do'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()

# 登录
driver.find_element(By.ID, 'taskId').clear()
driver.find_element(By.ID, 'taskId').send_keys('1')
driver.find_element(By.ID, 'loginName').clear()
driver.find_element(By.ID, 'loginName').send_keys('test03')
driver.find_element(By.ID, 'password').clear()
driver.find_element(By.ID, 'password').send_keys('123456')
driver.find_element(By.ID, 'vericode').clear()
driver.find_element(By.ID, 'vericode').send_keys('shtd')
sleep(3)
driver.find_element(By.XPATH, '//*[@id="fmedit"]/div[2]/div[6]/input').click()
sleep(3)

# 修改电话
driver.find_element(By.ID, 'phone').clear()
driver.find_element(By.ID, 'phone').send_keys('12345678901')
driver.find_element(By.LINK_TEXT, '保存').click()
sleep(3)

# 处理警告弹窗
# 获取本文
text = driver.switch_to.alert.text
print(text)
sleep(3)
# 点击确定按钮
driver.switch_to.alert.accept()
sleep(3)

# 修改密码
driver.find_element(By.LINK_TEXT, '修改密码').click()
driver.find_element(By.ID, 'oldPassword').clear()
driver.find_element(By.ID, 'oldPassword').send_keys('123456')
driver.find_element(By.ID, 'newPassword1').clear()
driver.find_element(By.ID, 'newPassword1').send_keys('123456')
driver.find_element(By.ID, 'newPassword2').clear()
driver.find_element(By.ID, 'newPassword2').send_keys('123456')
sleep(3)
driver.find_element(By.XPATH, '//*[@id="cboxLoadedContent"]/div/div/div[2]/div[4]/div[1]').click()
sleep(3)

# 弹窗警告
text = driver.switch_to.alert.text
print(text)
sleep(3)
# 点击确定按钮
driver.switch_to.alert.accept()
sleep(3)

# 退出
driver.find_element(By.LINK_TEXT, '退出').click()
sleep(3)

driver.quit()
